package org.p2psimulator.entity.behavior;


import org.p2psimulator.entity.Id;
import org.p2psimulator.entity.Message;
import org.p2psimulator.entity.reputation.Reputation;
import org.p2psimulator.entity.reputation.ReputationRepository;

public class HonestBehavior extends Behavior {

	@Override
	public boolean answareMessage(Id rater, Message msg) {
	interacitonCount++;
            return true;
	}

	@Override
	public boolean rate() {
		return true;
	}

	@Override
	public double ratePeer(Id rater, Id ratee,
			BehaviorTypes rateeBehavior,
			ReputationRepository repository) {

		try {
			Reputation reputation = repository.getLocalReputation(rater, ratee);
			if (reputation != null){
				return reputation.getAverageReputation();
			}else{
				return 0;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	@Override
	public double rateResource(Id rater, Id resource,
			ReputationRepository repository) {

		try {
			Reputation reputation = repository.getLocalReputation(rater,
					resource);
			if (reputation != null){
				return reputation.getNormalReputation();
			}else{
				return 0;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}

	@Override
	public double rateTransaction(Id rater, Id ratee, int transResult,
			BehaviorTypes rateeBehavior,
			ReputationRepository repository) {
	interacitonCount++;
            return transResult;
	}


	@Override
	public BehaviorTypes getBehaviorType() {
		return BehaviorTypes.HONEST;
	}

	@Override
	public boolean damageResource() {
		return false;
	}

	@Override
	public boolean transacNeutro(BehaviorTypes rateeBehavior, Id ratee) {
		return false;
	}
}
